#!/bin/sh -e

. ci/travis/lib.sh
. ci/travis/before_install_lib.sh

BOOST_PACKAGES_BASE="libboost libboost-regex libboost-date-time
	libboost-program-options libboost-test libboost-filesystem
	libboost-system libboost-thread"

handle_centos() {
	# First EPEL stuff
	yum install -y epel-release

	yum -y groupinstall 'Development Tools'
	# FIXME: remove python-mako & python-six when not building gnuradio
	yum -y install cmake boost-devel python-devel fftw-devel bison flex yum \
		python-mako python-six \
		swig git libusb1-devel doxygen libaio-devel avahi-devel bzip2 gzip \
		rpm rpm-build libxml2-devel

	__handle_common

	if [ "$TRAVIS" = "true" ] || [ "$INSIDE_DOCKER" = "1" ] ; then
		for pkg in libiio libad9361-iio ; do
			wget http://swdownloads.analog.com/cse/travis_builds/${LIBIIO_BRANCH}_latest_${pkg}${LDIST}.rpm
			sudo yum localinstall -y ./${LIBIIO_BRANCH}_latest_${pkg}${LDIST}.rpm
		done
	fi
}

handle_centos_docker() {
	prepare_docker_image "centos:centos${OS_VERSION}"
}

handle_ubuntu_docker() {
	prepare_docker_image "ubuntu:${OS_VERSION}"
}

handle_default() {
	local BOOST_PACKAGES

	for package in $BOOST_PACKAGES_BASE ; do
		BOOST_PACKAGES="$BOOST_PACKAGES ${package}${BOOST_VER}-dev"
	done

	sudo apt-get -qq update
	# FIXME: remove python-mako & python-six when not building gnuradio
	sudo apt-get install -y build-essential libboost-dev libpython-dev bison \
		flex git libfftw3-dev swig cmake libaio-dev libavahi-client-dev libavahi-common-dev \
		libusb-1.0-0-dev libxml2-dev tar bzip2 gzip \
		python-mako python-six \
		$BOOST_PACKAGES

	if apt-cache show libserialport-dev &> /dev/null ; then
		sudo apt-get install -y libserialport-dev
	fi

	__handle_common

	if [ "$TRAVIS" = "true" ] || [ "$INSIDE_DOCKER" = "1" ] ; then
		for pkg in libiio libad9361-iio ; do
			wget http://swdownloads.analog.com/cse/travis_builds/${LIBIIO_BRANCH}_latest_${pkg}${LDIST}.deb
			sudo dpkg -i ./${LIBIIO_BRANCH}_latest_${pkg}${LDIST}.deb
		done
	fi
}

LIBNAME="gr-iio"
OS_TYPE=${1:-default}
OS_VERSION="$2"

handle_${OS_TYPE}
